//
//  LJHCusAllViewController.m
//  HEARME
//
//  Created by liujinhui on 16/1/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LJHCusAllViewController.h"
#import "LJHHistoryViewController.h"
#import "LJHFavoriteViewController.h"
@interface LJHCusAllViewController ()<UIScrollViewDelegate>

@property(nonatomic,retain)UIScrollView *bigScrollView;
@property(nonatomic,retain)UIView *sliderView;
@property(nonatomic,retain)LJHBaseButton *favorBtn;
@property(nonatomic,retain)LJHBaseButton *historyBtn;

@end

@implementation LJHCusAllViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"定制听";
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:202/255.0 green:222/255.0 blue:239/255.0 alpha:1];
    
    [self createButton];
    [self createScrollView];
//    [self.view bringSubviewToFront:self.messageView];
    
    // Do any additional setup after loading the view.
}

-(void)createScrollView
{
    
    //外层scrollview
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    
    self.bigScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, WIDTH, HEIGHT-111)];
    self.bigScrollView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.bigScrollView];
    //    [_bigScrollView release];
    self.bigScrollView.contentSize = CGSizeMake(WIDTH*2, HEIGHT-111);
    self.bigScrollView.pagingEnabled = YES;
    self.bigScrollView.bounces = NO;
    self.bigScrollView.delegate = self;
    
    self.sliderView = [[UIView alloc] initWithFrame:CGRectMake(self.favorBtn.frame.origin.x, self.favorBtn.frame.origin.y+self.favorBtn.frame.size.height, self.favorBtn.frame.size.width, 2)];
    self.sliderView.backgroundColor = [UIColor colorWithRed:0.98 green:0.35 blue:0.16 alpha:1];
    [self.view addSubview:self.sliderView];
    [_sliderView release];
    
    LJHFavoriteViewController *favorVC = [[LJHFavoriteViewController alloc] init];
    [self addChildViewController:favorVC];
    [self.bigScrollView addSubview:favorVC.view];
    LJHHistoryViewController *historyVC = [[LJHHistoryViewController alloc] init];
    [self addChildViewController:historyVC];
    historyVC.view.frame = CGRectMake(WIDTH, 0, WIDTH, HEIGHT);
    [self.bigScrollView addSubview:historyVC.view];
}

-(void)createButton
{
    
    //推荐按钮
    self.favorBtn = [LJHBaseButton buttonWithType:UIButtonTypeCustom];
    self.favorBtn.frame = CGRectMake(0, 0, WIDTH/2, 40);
    [self.favorBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.favorBtn setTitle:@"收藏" forState:UIControlStateNormal];
    self.favorBtn.titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    [self.view addSubview:self.favorBtn];
    [self.favorBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //分类按钮
    self.historyBtn = [LJHBaseButton buttonWithType:UIButtonTypeCustom];
    self.historyBtn.frame = CGRectMake(self.favorBtn.frame.origin.x+self.favorBtn.frame.size.width, 0, WIDTH/2, self.favorBtn.frame.size.height);
    [self.historyBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    [self.historyBtn setTitle:@"历史" forState:UIControlStateNormal];
    self.historyBtn.titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    [self.view addSubview:self.historyBtn];
    [self.historyBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)buttonAction:(UIButton *)btn
{
    if (btn == self.favorBtn) {
        [self.bigScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
        
    }
    else
    {
        [self.bigScrollView setContentOffset:CGPointMake(WIDTH, 0) animated:YES];
    }
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    self.sliderView.frame = CGRectMake(self.bigScrollView.contentOffset.x/2 , self.favorBtn.frame.origin.y+self.favorBtn.frame.size.height, self.favorBtn.frame.size.width, 2);
    
    if (self.bigScrollView.contentOffset.x==0) {
        [self.favorBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [self.historyBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    }
    if (self.bigScrollView.contentOffset.x==WIDTH) {
        [self.favorBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self.historyBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
